'''
4.3.2 继承与多态
'''

class People(object):
    # 初始化方法
    def __init__(self, name, age):
        self.name = name
        self.age = age

    # 类中的方法
    def talk(self):
        print(f'你好{self.name}，今年我{self.age}岁')

# Student类继承People
class Student(People):
    def __init__(self, name, age, school):
        super().__init__(name, age)
        self.school = school
    
    def talk(self):
        super().talk()
        print(f'在{self.school}上学')

# Teacher类继承People
class Teacher(People):
    def __init__(self, name, age, school):
        super().__init__(name, age)
        self.school = school
    
    def talk(self):
        super().talk()
        print(f'在{self.school}教书')

s = Student('学生二两', 28, '社会大学')
s.talk() # 直接使用父类方法

t = Teacher('张三老师', 38, '社会大学')
t.talk()

print(isinstance(s, People))
print(isinstance(t, People))

def talk_something(people):
    if isinstance(people, People):
        people.talk()

s = Student('学生二两', 28, '社会大学')
t = Teacher('张三老师', 38, '社会大学')
talk_something(s)
talk_something(t)

class Programmer(People):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def talk(self):
        super().talk()
        print('我爱编程')

p = Programmer('程序员李四', 44)
talk_something(p)